package eu.dicode.analysis.demonstrator.model;

import java.util.SortedSet;
import java.util.TreeSet;

import org.springframework.util.StringUtils;

public class Topiccommand {
  private String label;

  private SortedSet<String> queries;

  public Topiccommand() {
    this("");
  }
  
  public Topiccommand(String label) {
    this.label = label;
    this.queries = new TreeSet<String>();
  }

  public void setLabel(String label) {
    this.label = label;
  }

  public String getLabel() {
    return label;
  }

  public void setQueries(SortedSet<String> queries) {
    this.queries = queries;
  }
  
  public void setQueries(String queries) {
    this.queries.clear();
    String[] splitedQueries = queries.split(",");    
    for (String query : splitedQueries) {
      query = query.trim();
      if (query.length() > 0){
	this.queries.add(query);
      }
    }
  }

  public SortedSet<String> getQueries() {
    return queries;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((label == null) ? 0 : label.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    Topiccommand other = (Topiccommand) obj;
    if (label == null) {
      if (other.label != null)
	return false;
    } else if (!label.equals(other.label))
      return false;
    return true;
  }

}
